<%--
Created by IntelliJ IDEA.
User: 92060
Date: 2021/12/25
Time: 14:20
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>


	<script>

		$(function () {
			if(window.top!=window){
				window.top.location=window.location;
			}
			$("#register").click(function () {
				regis();
			});
			//页面加载完毕后，将用户文本框中的内容清空
			$("#loginAct").val("");
			//页面加载完毕后，让用户的文本框自动获得焦点
			$("#loginAct").focus();
			//为登录按钮绑定事件，执行登录操作
			$("#submitBtn").click(function () {
				login();
			})
			//为当前登录也窗口绑定敲键盘事件
			//event:这个参数可以取得我们敲的是哪个键
			$(window).keydown(function (event) {
				//alert(event.keyCode);
				//如果取得的键位的码值为13，表示敲的是回车键
				if(event.keyCode==13){
					login();
				}
			})
		})
		//普通的自定义的function方法，一定要写在$(function(){})的外面
		function login() {
			//alert("登录操作123");
			//验证账号密码不能为空
			//取得账号密码
			//将文本中的左右空格去掉，使用$.trim(文本)
			var loginAct = $.trim($("#loginAct").val());
			var loginPwd = $.trim($("#loginPwd").val());
			if(loginAct=="" || loginPwd==""){
				$("#msg").html("账号密码不能为空");
				//如果账号密码为空，则需要及时强制终止该方法
				return false;
			}
			//去后台验证登录相关操作
			$.ajax({
				url : "settings/user/login",
				data : {
					"loginAct" : loginAct,
					"loginPwd" : loginPwd
				},
				type : "post",
				dataType : "json",
				success : function (data) {
					console.log(data)
					//如果登录成功
					if(data.success){
						sessionStorage.setItem("username",loginAct);
						sessionStorage.setItem("password",loginPwd);
						findid(loginAct)
						//跳转到工作台的初始也（欢迎页）
						window.location.href = "client/index.jsp";
						//如果登录失败
					}else{
						$("#msg").html(data.msg);
					}
				}
			})
		}
		function findid(name) {
			$.ajax({
				url : "settings/user/findid",
				data : {
					"username" : name,
				},
				type : "get",
				dataType : "json",
				success : function (data) {
					var uid = data
					sessionStorage.setItem("uid",uid);
				}
			})
		}
		function regis(){
			var user = $.trim($("#user").val());
			var pass = $.trim($("#pass").val());
			var twopass = $.trim($("#twopass").val());
			if(user=="" || pass=="" ||twopass==""){
				alert("用户密码不能为空");
				//如果账号密码为空，则需要及时强制终止该方法
				return false;
			}else if(pass!=twopass){
				alert("两次密码不一致")
				return false;
			}
			/*发起注册请求*/
			$.ajax({
				url : "${pageContext.request.contextPath}/settings/user/registers",
				data : {
					"loginAct" : user,
					"loginPwd" : pass
				},
				type : "post",
				dataType : "json",
				success : function (data) {
					if(data.success){
						alert("注册成功")
						window.location.reload()
					}
				}
			})
		}

	</script>
</head>

<body>
<%--修改信息模态框--%>
<div class="modal fade" id="selfregister" role="dialog">
	<div class="modal-dialog" role="document" style="width: 30%;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">
					<span aria-hidden="true">×</span>
				</button>
				<h4 class="modal-title">注册</h4>
			</div>
			<div class="modal-body">
				<div style="text-align: left">
					<br>
					<label>用户名:</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="text" id="user" placeholder="请输入用户名">
					<br>
					<br>
					<label>密 &nbsp; 码:</label>&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="text" id="pass" placeholder="请输入密码">
					<br>
					<br>
					<label>确认密码:</label>
					<input type="text" id="twopass" placeholder="请再次输入密码">
					<br>
				</div>
			</div>
			<div class="modal-footer">
				<button id="register" type="button" class="btn btn-primary" >确定注册</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>


	<div style="position: absolute; top: 0px; left: 0px; width: 60%;">
		<img src="image/IMG_7114.JPG" style="width: 100%; height: 90%; position: relative; top: 50px;">
	</div>
	<div id="top" style="height: 50px; background-color: #3C3C3C; width: 100%;">
		<div style="position: absolute; top: 5px; left: 0px; font-size: 30px; font-weight: 400; color: white; font-family: 'times new roman'">好物到家</div>
	</div>
	
	<div style="position: absolute; top: 120px; right: 100px;width:450px;height:400px;border:1px solid #D5D5D5">
		<div style="position: absolute; top: 0px; right: 60px;">
			<div class="page-header">
				<h1>登录</h1>
			</div>
			<form action="workbench/index.html" class="form-horizontal" role="form">
				<div class="form-group form-group-lg">
					<div style="width: 350px;">
						<input class="form-control" id="loginAct" type="text" placeholder="用户名">
					</div>
					<div style="width: 350px; position: relative;top: 20px;">
						<input class="form-control" id="loginPwd" type="password" placeholder="密码">
					</div>
					<div class="checkbox"  style="position: relative;top: 30px; left: 10px;">
						
							<span id="msg" style="color: red"></span>
						
					</div>
					<button type="button" id="submitBtn" class="btn btn-primary btn-lg btn-block"  style="width: 350px; position: relative;top: 45px;">登录</button>
					<button  data-toggle="modal" data-target="#selfregister" type="button" id="insertuser" class="btn btn-info btn-lg btn-block"  style="width: 350px; position: relative;top: 45px;">注册</button>
				</div>
			</form>
		</div>
	</div>
</body>
</html>